Imports System.Data
Partial Class Client_frmEditQuantity
    Inherits System.Web.UI.Page
    Dim _ProductId As String
    Dim _bo As New Bo
    Dim _UserId As String
    Dim dt As New DataTable
    Dim _AvailableQuantity As String
    Dim _AddToCartVo As New AddToCartVo
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Empid") = "" Then
            _UserId = Session("UserId")
            If _UserId = "" Then
                Response.Redirect("frmDataList.aspx")
            End If
            _ProductId = Request.QueryString("ProductId")
            If _ProductId = "" Then
                Response.Redirect("frmShowCart.aspx")
            End If
            dt = _bo.getCartByProduct(_ProductId, _UserId)
            lblBrand.Text = dt.Rows(0).Item(5).ToString
            lblPrice.Text = dt.Rows(0).Item(2).ToString
            img.ImageUrl = dt.Rows(0).Item(4).ToString
            lblDiscount.Text = dt.Rows(0).Item(7).ToString
            _AvailableQuantity = dt.Rows(0).Item(8).ToString
            ddl1.SelectedValue = dt.Rows(0).Item(9).ToString
        Else

        End If
    End Sub
    Sub calculate()
        dt = _bo.getCartByProduct(_ProductId, _UserId)
        _bo.DeleteFromCart(_UserId, _ProductId)
        Dim _TotalAmount As Integer
        _AddToCartVo.ProductId = _ProductId
        _AddToCartVo.Quantity = txtQuantity.Text
        _AddToCartVo.UserId = _UserId
        _AddToCartVo.OriginalPrice = Integer.Parse(dt.Rows(0).Item(2).ToString) * Val(txtQuantity.Text)
        Dim dis As Integer = Val(dt.Rows(0).Item(7).ToString)
        Dim Originalprice As Integer = Val(dt.Rows(0).Item(2).ToString)
        _TotalAmount = (Originalprice - ((dis * Originalprice) / 100)) * Val(txtQuantity.Text)
        _AddToCartVo.DiscountedPrice = _TotalAmount
    End Sub
    Protected Sub lnkbtn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles lnkbtn.Click
        If _UserId = "" Then
            Response.Redirect("frmLogin.aspx")
        End If
        If txtQuantity.Text = "" Then
            txtQuantity.Text = "1"
        End If
        If _AvailableQuantity < Val(txtQuantity.Text) Then
            MsgBox("Quantity Not In Stock ")
        Else
            Call calculate()
            _bo.AddToCart(_AddToCartVo)
            Response.Redirect("frmShowCart.aspx")
        End If
    End Sub
End Class
